<?php
/**
 * 管理中心· 欢迎页模块的逻辑处理
 * ============================================================================
 * 版权所有 2017-2020 北京优特世纪科技有限公司，并保留所有权利。
 * 网站地址: http://www.unitewww.com;
 * ============================================================================
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用；
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * @since: 1.0
 * @version: 1.0
 **/
namespace Hoteladmin\Controller;
use Hoteladmin\Model\SetupModel;
class IndexController extends BaseController {
    //初始化程序
    public function _initialize()
    {
        parent::_initialize();
        $adid = session('admin_auth.usid');
        //实例化相关表
        $meident = M('message');
        $adident = M('admin');
        //查询当前登录管理员name
        $adname = $adident->where("`ad_id`='".$adid."'")->field('ad_name')->find();
        $count = $meident->where("`me_suid`='".$adname['ad_name']."' and `me_slook`= 0 and `me_sstate`= 1")->count();
        $this->assign('count',$count);
    }
    /**
     +--------------------------------------------------------------------------
     * 实现后台首页页面
     * @author:  XC跃
     * @date :2018-05-06
     +--------------------------------------------------------------------------
     */
    public function index(){
        $config = tpCache("sBas");
        $this->assign('xc_config', $config);
        $this->display();
    }
    /**
     +--------------------------------------------------------------------------
     * 实现欢迎页的功能
     * @author:  XC跃
     * @date :2018-05-06
     +--------------------------------------------------------------------------
     */
    public function welcome(){
        $adid = session('admin_auth.usid');
        //实例化相关表
        $adident = M('admin');
        //实例化相关Model
        $identr = new SetupModel();
        //获取登陆信息
        $info = $adident->where("`ad_id`='".$adid."'")->find();
        $icou = $identr->index_count();
        $this->assign("icou",$icou); //信息统计
        $this->assign('sys_info',$identr->get_sys_info());
        $this->assign('ainfo',$info);
        $this->display();
    }
    /**
     +--------------------------------------------------------------------------
     * 实现修改角色信息的功能
     * @author :XC跃
     * @date:2018-02-04
     +--------------------------------------------------------------------------
     */
    public function adminEdit(){
        $aid = session('admin_auth.usid');
        //实例化相关类
        $ident = M('admin');
        if(IS_POST){
            $aid = trim(I('post.aid'));
            $pwds= trim(I('post.pwds'));
            $data['ad_name'] = $uname = trim(I('post.uname'));
            $data['ad_phone']= trim(I('post.phone'));
            $data['ad_email']= trim(I('post.email'));
            if(''!=$pwds){
                $data['ad_pwd'] = MD5($pwds);
            }
            $re = $ident->where("`ad_id`='".$aid."'")->save($data);
            //日志
            addLog($uname,'2','2','编辑个人资料信息');
            if($re>0){
                $res = array('status'=>1,'msg'=>'个人信息编辑成功');
                exit(json_encode($res));
            }
        }else{
            $list = $ident->where("`ad_id`='".$aid."'")->find();
            $this->assign("list",$list);
            $this->display();
        }
    }
    /**
     +--------------------------------------------------------------------------
     * 实现验证客户信息是否重复
     * @author:  XC跃
     * @date :2018-02-04
     +--------------------------------------------------------------------------
     */
//     public function verCustomName(){
//         $table = I('post.table');
//         $field = I('post.field');
//         $value = I('post.value');
//         $re = M($table)->where("`".$value."` = '".$field."'")->find();
//         if('0'==count($re)){
//             $res = array('status'=>1,'msg'=>'可以使用');
//         }
//         exit(json_encode($res));
//     }
    
    /**
     +--------------------------------------------------------------------------
     * 实现退出后台管理系统
     * @author:  XC跃
     * @date :2017-04-01
     +--------------------------------------------------------------------------
     */
    public function quit(){
        //删除SESSION
        session(null);
        $res = array('status'=>1,'msg'=>'注销成功！','url'=>'/Hoteladmin/Login/login');
        exit(json_encode($res));
    }
    /**
     +--------------------------------------------------------------------------
     * 实现清空系统缓存的功能
     * @author:  XC跃
     * @date :2018-01-08
     +--------------------------------------------------------------------------
     */
    public function clearC(){
        $dir="./Runtime";
        clearCache($dir);  //清空缓存文件
        $res = array('status'=>1,'msg'=>'缓存清除成功！','url'=>U('Index/index'));
        exit(json_encode($res));
    }
    /**
     +--------------------------------------------------------------------------
     * 实现管理员批量删除数据
     * @author: XC跃
     * @date :2017-04-01
     +--------------------------------------------------------------------------
     */
    function delData(){
        $tab = I('post.tab');
        $val = I('post.val');
        $id  = I('post.ids');
        //实例化相关表
        $ident = M($tab);
        if(empty($id)){
            $res = array('status'=>-1,'msg'=>'未选中需要删除数据');
            exit(json_encode($res));
        }
        $ids = implode(",",$id);
        $re = $ident->where($val." in(".$ids.")")->delete();
        //日志
        //addLog('2', "批量删除".count($id)."数据");
        if($re>0){
            $res = array('status'=>1,'info'=>'删除多条数据成功');
            exit(json_encode($res));
        }
    }
}